.class public Lorg/microemu/app/util/FileRecordStoreManager;
.super Ljava/lang/Object;
.source "FileRecordStoreManager.java"

# interfaces
.implements Lorg/microemu/RecordStoreManager;


# static fields
.field private static final RECORD_STORE_SUFFIX:Ljava/lang/String; = ".rs"

.field private static final replaceChars:Ljava/util/List;


# instance fields
.field private acc:Ljava/security/AccessControlContext;

.field private emulator:Lorg/microemu/MicroEmulator;

.field private filter:Ljava/io/FilenameFilter;

.field private recordListener:Lorg/microemu/util/ExtendedRecordListener;

.field private testOpenRecordStores:Ljava/util/Hashtable;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    .line 60
    new-instance v0, Ljava/util/Vector;

    invoke-direct {v0}, Ljava/util/Vector;-><init>()V

    sput-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    .line 72
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, ":"

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 73
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "*"

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 74
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "?"

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 75
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "="

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 76
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "|"

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 77
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "/"

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 78
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "\\"

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 79
    sget-object v0, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    const-string v1, "\""

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 80
    return-void
.end method

.method public constructor <init>()V
    .locals 1

    .prologue
    .line 56
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 64
    new-instance v0, Ljava/util/Hashtable;

    invoke-direct {v0}, Ljava/util/Hashtable;-><init>()V

    iput-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->testOpenRecordStores:Ljava/util/Hashtable;

    .line 66
    const/4 v0, 0x0

    iput-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    .line 82
    new-instance v0, Lorg/microemu/app/util/FileRecordStoreManager$1;

    invoke-direct {v0, p0}, Lorg/microemu/app/util/FileRecordStoreManager$1;-><init>(Lorg/microemu/app/util/FileRecordStoreManager;)V

    iput-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->filter:Ljava/io/FilenameFilter;

    return-void
.end method

.method static access$000(Lorg/microemu/app/util/FileRecordStoreManager;)Ljava/io/FilenameFilter;
    .locals 1
    .parameter "x0"

    .prologue
    .line 56
    iget-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->filter:Ljava/io/FilenameFilter;

    return-object v0
.end method

.method static access$100(Lorg/microemu/app/util/FileRecordStoreManager;)Ljava/io/File;
    .locals 1
    .parameter "x0"

    .prologue
    .line 56
    invoke-direct {p0}, Lorg/microemu/app/util/FileRecordStoreManager;->getSuiteFolder()Ljava/io/File;

    move-result-object v0

    return-object v0
.end method

.method static access$200(Lorg/microemu/app/util/FileRecordStoreManager;Ljava/io/File;)Lorg/microemu/util/RecordStoreImpl;
    .locals 1
    .parameter "x0"
    .parameter "x1"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/FileNotFoundException;
        }
    .end annotation

    .prologue
    .line 56
    invoke-direct {p0, p1}, Lorg/microemu/app/util/FileRecordStoreManager;->loadFromDiskSecure(Ljava/io/File;)Lorg/microemu/util/RecordStoreImpl;

    move-result-object v0

    return-object v0
.end method

.method static access$300(Lorg/microemu/app/util/FileRecordStoreManager;Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V
    .locals 0
    .parameter "x0"
    .parameter "x1"
    .parameter "x2"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 56
    invoke-direct {p0, p1, p2}, Lorg/microemu/app/util/FileRecordStoreManager;->saveToDiskSecure(Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V

    return-void
.end method

.method private static escapeCharacter(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "charcter"

    .prologue
    .line 106
    new-instance v0, Ljava/lang/StringBuffer;

    invoke-direct {v0}, Ljava/lang/StringBuffer;-><init>()V

    const-string v1, "_%%"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v0

    const/4 v1, 0x0

    invoke-virtual {p0, v1}, Ljava/lang/String;->charAt(I)C

    move-result v1

    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(I)Ljava/lang/StringBuffer;

    move-result-object v0

    const-string v1, "%%_"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method static fileName2RecordStoreName(Ljava/lang/String;)Ljava/lang/String;
    .locals 6
    .parameter "fileName"

    .prologue
    .line 123
    sget-object v3, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    invoke-interface {v3}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, iterator:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_1

    .line 124
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 125
    .local v0, c:Ljava/lang/String;
    invoke-static {v0}, Lorg/microemu/app/util/FileRecordStoreManager;->escapeCharacter(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    .line 126
    .local v2, newValue:Ljava/lang/String;
    const-string v3, "\\"

    invoke-virtual {v0, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-eqz v3, :cond_0

    .line 127
    const-string v0, "\\\\"

    .line 129
    :cond_0
    invoke-virtual {p0, v2, v0}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    .line 130
    goto :goto_0

    .line 131
    .end local v2           #newValue:Ljava/lang/String;
    .end local v0           #c:Ljava/lang/String;
    :cond_1
    const/4 v3, 0x0

    invoke-virtual {p0}, Ljava/lang/String;->length()I

    move-result v4

    const-string v5, ".rs"

    invoke-virtual {v5}, Ljava/lang/String;->length()I

    move-result v5

    sub-int/2addr v4, v5

    invoke-virtual {p0, v3, v4}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v3

    return-object v3
.end method

.method private getSuiteFolder()Ljava/io/File;
    .locals 4

    .prologue
    .line 102
    new-instance v0, Ljava/io/File;

    invoke-static {}, Lorg/microemu/app/Config;->getConfigPath()Ljava/io/File;

    move-result-object v1

    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    const-string v3, "suite-"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    iget-object v3, p0, Lorg/microemu/app/util/FileRecordStoreManager;->emulator:Lorg/microemu/MicroEmulator;

    invoke-interface {v3}, Lorg/microemu/MicroEmulator;->getLauncher()Lorg/microemu/app/launcher/Launcher;

    move-result-object v3

    invoke-virtual {v3}, Lorg/microemu/app/launcher/Launcher;->getSuiteName()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    return-object v0
.end method

.method private loadFromDisk(Ljava/io/File;)Lorg/microemu/util/RecordStoreImpl;
    .locals 3
    .parameter "recordStoreFile"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/FileNotFoundException;
        }
    .end annotation

    .prologue
    .line 236
    :try_start_0
    new-instance v1, Lorg/microemu/app/util/FileRecordStoreManager$4;

    invoke-direct {v1, p0, p1}, Lorg/microemu/app/util/FileRecordStoreManager$4;-><init>(Lorg/microemu/app/util/FileRecordStoreManager;Ljava/io/File;)V

    iget-object v2, p0, Lorg/microemu/app/util/FileRecordStoreManager;->acc:Ljava/security/AccessControlContext;

    invoke-static {v1, v2}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Lorg/microemu/util/RecordStoreImpl;
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_0

    return-object p0

    .line 241
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 242
    .local v0, e:Ljava/security/PrivilegedActionException;
    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object v1

    instance-of v1, v1, Ljava/io/FileNotFoundException;

    if-eqz v1, :cond_0

    .line 243
    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object p0

    check-cast p0, Ljava/io/FileNotFoundException;

    throw p0

    .line 245
    :cond_0
    new-instance v1, Ljava/lang/StringBuffer;

    invoke-direct {v1}, Ljava/lang/StringBuffer;-><init>()V

    const-string v2, "Unable access file "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v1

    invoke-virtual {v1, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/Object;)Ljava/lang/StringBuffer;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1, v0}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 246
    new-instance v1, Ljava/io/FileNotFoundException;

    invoke-direct {v1}, Ljava/io/FileNotFoundException;-><init>()V

    throw v1
.end method

.method private loadFromDiskSecure(Ljava/io/File;)Lorg/microemu/util/RecordStoreImpl;
    .locals 6
    .parameter "recordStoreFile"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/FileNotFoundException;
        }
    .end annotation

    .prologue
    .line 251
    const/4 v2, 0x0

    .line 253
    .local v2, store:Lorg/microemu/util/RecordStoreImpl;
    :try_start_0
    new-instance v0, Ljava/io/DataInputStream;

    new-instance v4, Ljava/io/FileInputStream;

    invoke-direct {v4, p1}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V

    invoke-direct {v0, v4}, Ljava/io/DataInputStream;-><init>(Ljava/io/InputStream;)V

    .line 254
    .local v0, dis:Ljava/io/DataInputStream;
    new-instance v3, Lorg/microemu/util/RecordStoreImpl;

    invoke-direct {v3, p0, v0}, Lorg/microemu/util/RecordStoreImpl;-><init>(Lorg/microemu/RecordStoreManager;Ljava/io/DataInputStream;)V
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1

    .line 255
    .local v3, store:Lorg/microemu/util/RecordStoreImpl;
    :try_start_1
    invoke-virtual {v0}, Ljava/io/DataInputStream;->close()V
    :try_end_1
    .catch Ljava/io/FileNotFoundException; {:try_start_1 .. :try_end_1} :catch_3
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_2

    .end local v2           #store:Lorg/microemu/util/RecordStoreImpl;
    move-object v2, v3

    .line 261
    .end local v0           #dis:Ljava/io/DataInputStream;
    .end local v3           #store:Lorg/microemu/util/RecordStoreImpl;
    .restart local v2       #store:Lorg/microemu/util/RecordStoreImpl;
    :goto_0
    return-object v2

    .line 256
    :catch_0
    move-exception v4

    move-object v1, v4

    .line 257
    .local v1, e:Ljava/io/FileNotFoundException;
    :goto_1
    throw v1

    .line 258
    .end local v1           #e:Ljava/io/FileNotFoundException;
    :catch_1
    move-exception v4

    move-object v1, v4

    .line 259
    .local v1, e:Ljava/io/IOException;
    :goto_2
    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "RecordStore.loadFromDisk: ERROR reading "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v4, v1}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    goto :goto_0

    .line 258
    .end local v2           #store:Lorg/microemu/util/RecordStoreImpl;
    .end local v1           #e:Ljava/io/IOException;
    .restart local v0       #dis:Ljava/io/DataInputStream;
    .restart local v3       #store:Lorg/microemu/util/RecordStoreImpl;
    :catch_2
    move-exception v4

    move-object v1, v4

    move-object v2, v3

    .restart local v2       #store:Lorg/microemu/util/RecordStoreImpl;
    goto :goto_2

    .line 256
    .end local v2           #store:Lorg/microemu/util/RecordStoreImpl;
    :catch_3
    move-exception v4

    move-object v1, v4

    move-object v2, v3

    .restart local v2       #store:Lorg/microemu/util/RecordStoreImpl;
    goto :goto_1
.end method

.method static recordStoreName2FileName(Ljava/lang/String;)Ljava/lang/String;
    .locals 5
    .parameter "recordStoreName"

    .prologue
    .line 110
    sget-object v3, Lorg/microemu/app/util/FileRecordStoreManager;->replaceChars:Ljava/util/List;

    invoke-interface {v3}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, iterator:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_1

    .line 111
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 112
    .local v0, c:Ljava/lang/String;
    invoke-static {v0}, Lorg/microemu/app/util/FileRecordStoreManager;->escapeCharacter(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    .line 113
    .local v2, newValue:Ljava/lang/String;
    const-string v3, "\\"

    invoke-virtual {v0, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-eqz v3, :cond_0

    .line 114
    const-string v0, "\\\\"

    .line 116
    :cond_0
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    const-string v4, "["

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3, v0}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    const-string v4, "]"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v0

    .line 117
    .restart local v0       #c:Ljava/lang/String;
    invoke-virtual {p0, v0, v2}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    .line 118
    goto :goto_0

    .line 119
    .end local v2           #newValue:Ljava/lang/String;
    .end local v0           #c:Ljava/lang/String;
    :cond_1
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    invoke-virtual {v3, p0}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    const-string v4, ".rs"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v3

    return-object v3
.end method

.method private saveToDisk(Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V
    .locals 3
    .parameter "recordStoreFile"
    .parameter "recordStore"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 266
    :try_start_0
    new-instance v1, Lorg/microemu/app/util/FileRecordStoreManager$5;

    invoke-direct {v1, p0, p1, p2}, Lorg/microemu/app/util/FileRecordStoreManager$5;-><init>(Lorg/microemu/app/util/FileRecordStoreManager;Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V

    iget-object v2, p0, Lorg/microemu/app/util/FileRecordStoreManager;->acc:Ljava/security/AccessControlContext;

    invoke-static {v1, v2}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_0

    .line 279
    return-void

    .line 272
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 273
    .local v0, e:Ljava/security/PrivilegedActionException;
    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object v1

    instance-of v1, v1, Ljavax/microedition/rms/RecordStoreException;

    if-eqz v1, :cond_0

    .line 274
    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object p0

    .end local p0
    check-cast p0, Ljavax/microedition/rms/RecordStoreException;

    throw p0

    .line 276
    .restart local p0
    :cond_0
    new-instance v1, Ljava/lang/StringBuffer;

    invoke-direct {v1}, Ljava/lang/StringBuffer;-><init>()V

    const-string v2, "Unable access file "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v1

    invoke-virtual {v1, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/Object;)Ljava/lang/StringBuffer;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1, v0}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 277
    new-instance v1, Ljavax/microedition/rms/RecordStoreException;

    invoke-direct {v1}, Ljavax/microedition/rms/RecordStoreException;-><init>()V

    throw v1
.end method

.method private saveToDiskSecure(Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V
    .locals 4
    .parameter "recordStoreFile"
    .parameter "recordStore"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 283
    invoke-virtual {p1}, Ljava/io/File;->getParentFile()Ljava/io/File;

    move-result-object v2

    invoke-virtual {v2}, Ljava/io/File;->exists()Z

    move-result v2

    if-nez v2, :cond_0

    .line 284
    invoke-virtual {p1}, Ljava/io/File;->getParentFile()Ljava/io/File;

    move-result-object v2

    invoke-virtual {v2}, Ljava/io/File;->mkdirs()Z

    move-result v2

    if-nez v2, :cond_0

    .line 285
    new-instance v2, Ljavax/microedition/rms/RecordStoreException;

    const-string v3, "Unable to create recordStore directory"

    invoke-direct {v2, v3}, Ljavax/microedition/rms/RecordStoreException;-><init>(Ljava/lang/String;)V

    throw v2

    .line 289
    :cond_0
    :try_start_0
    new-instance v0, Ljava/io/DataOutputStream;

    new-instance v2, Ljava/io/FileOutputStream;

    invoke-direct {v2, p1}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V

    invoke-direct {v0, v2}, Ljava/io/DataOutputStream;-><init>(Ljava/io/OutputStream;)V

    .line 290
    .local v0, dos:Ljava/io/DataOutputStream;
    invoke-virtual {p2, v0}, Lorg/microemu/util/RecordStoreImpl;->write(Ljava/io/DataOutputStream;)V

    .line 291
    invoke-virtual {v0}, Ljava/io/DataOutputStream;->close()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    .line 296
    return-void

    .line 292
    .end local v0           #dos:Ljava/io/DataOutputStream;
    :catch_0
    move-exception v2

    move-object v1, v2

    .line 293
    .local v1, e:Ljava/io/IOException;
    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    const-string v3, "RecordStore.saveToDisk: ERROR writting object to "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2, v1}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 294
    new-instance v2, Ljavax/microedition/rms/RecordStoreException;

    invoke-virtual {v1}, Ljava/io/IOException;->getMessage()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljavax/microedition/rms/RecordStoreException;-><init>(Ljava/lang/String;)V

    throw v2
.end method


# virtual methods
.method public deleteRecordStore(Ljava/lang/String;)V
    .locals 6
    .parameter "recordStoreName"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreNotFoundException;,
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 136
    new-instance v3, Ljava/io/File;

    invoke-direct {p0}, Lorg/microemu/app/util/FileRecordStoreManager;->getSuiteFolder()Ljava/io/File;

    move-result-object v4

    invoke-static {p1}, Lorg/microemu/app/util/FileRecordStoreManager;->recordStoreName2FileName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v3, v4, v5}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 138
    .local v3, storeFile:Ljava/io/File;
    iget-object v4, p0, Lorg/microemu/app/util/FileRecordStoreManager;->testOpenRecordStores:Ljava/util/Hashtable;

    invoke-virtual {v3}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/util/Hashtable;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lorg/microemu/util/RecordStoreImpl;

    .line 139
    .local v2, recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    if-eqz v2, :cond_0

    invoke-virtual {v2}, Lorg/microemu/util/RecordStoreImpl;->isOpen()Z

    move-result v4

    if-eqz v4, :cond_0

    .line 140
    new-instance v4, Ljavax/microedition/rms/RecordStoreException;

    invoke-direct {v4}, Ljavax/microedition/rms/RecordStoreException;-><init>()V

    throw v4

    .line 144
    :cond_0
    :try_start_0
    invoke-direct {p0, v3}, Lorg/microemu/app/util/FileRecordStoreManager;->loadFromDisk(Ljava/io/File;)Lorg/microemu/util/RecordStoreImpl;
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v2

    .line 150
    :try_start_1
    new-instance v4, Lorg/microemu/app/util/FileRecordStoreManager$2;

    invoke-direct {v4, p0, v3, p1}, Lorg/microemu/app/util/FileRecordStoreManager$2;-><init>(Lorg/microemu/app/util/FileRecordStoreManager;Ljava/io/File;Ljava/lang/String;)V

    iget-object v5, p0, Lorg/microemu/app/util/FileRecordStoreManager;->acc:Ljava/security/AccessControlContext;

    invoke-static {v4, v5}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    :try_end_1
    .catch Ljava/security/PrivilegedActionException; {:try_start_1 .. :try_end_1} :catch_1

    .line 161
    return-void

    .line 145
    :catch_0
    move-exception v1

    .line 146
    .local v1, ex:Ljava/io/FileNotFoundException;
    new-instance v4, Ljavax/microedition/rms/RecordStoreNotFoundException;

    invoke-direct {v4, p1}, Ljavax/microedition/rms/RecordStoreNotFoundException;-><init>(Ljava/lang/String;)V

    throw v4

    .line 157
    .end local v1           #ex:Ljava/io/FileNotFoundException;
    :catch_1
    move-exception v4

    move-object v0, v4

    .line 158
    .local v0, e:Ljava/security/PrivilegedActionException;
    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "Unable remove file "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/Object;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v4, v0}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 159
    new-instance v4, Ljavax/microedition/rms/RecordStoreException;

    invoke-direct {v4}, Ljavax/microedition/rms/RecordStoreException;-><init>()V

    throw v4
.end method

.method public deleteStores()V
    .locals 5

    .prologue
    .line 223
    invoke-virtual {p0}, Lorg/microemu/app/util/FileRecordStoreManager;->listRecordStores()[Ljava/lang/String;

    move-result-object v3

    .line 224
    .local v3, stores:[Ljava/lang/String;
    const/4 v1, 0x0

    .local v1, i:I
    :goto_0
    array-length v4, v3

    if-ge v1, v4, :cond_0

    .line 225
    aget-object v2, v3, v1

    .line 227
    .local v2, store:Ljava/lang/String;
    :try_start_0
    invoke-virtual {p0, v2}, Lorg/microemu/app/util/FileRecordStoreManager;->deleteRecordStore(Ljava/lang/String;)V
    :try_end_0
    .catch Ljavax/microedition/rms/RecordStoreException; {:try_start_0 .. :try_end_0} :catch_0

    .line 224
    :goto_1
    add-int/lit8 v1, v1, 0x1

    goto :goto_0

    .line 228
    :catch_0
    move-exception v0

    .line 229
    .local v0, e:Ljavax/microedition/rms/RecordStoreException;
    const-string v4, "deleteRecordStore"

    invoke-static {v4, v0}, Lorg/microemu/log/Logger;->debug(Ljava/lang/String;Ljava/lang/Throwable;)V

    goto :goto_1

    .line 232
    .end local v2           #store:Ljava/lang/String;
    .end local v0           #e:Ljavax/microedition/rms/RecordStoreException;
    :cond_0
    return-void
.end method

.method public fireRecordStoreListener(ILjava/lang/String;)V
    .locals 3
    .parameter "type"
    .parameter "recordStoreName"

    .prologue
    .line 308
    iget-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    if-eqz v0, :cond_0

    .line 309
    iget-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v1

    invoke-interface {v0, p1, v1, v2, p2}, Lorg/microemu/util/ExtendedRecordListener;->recordStoreEvent(IJLjava/lang/String;)V

    .line 311
    :cond_0
    return-void
.end method

.method public getName()Ljava/lang/String;
    .locals 1

    .prologue
    .line 98
    const-string v0, "File record store"

    return-object v0
.end method

.method public getSizeAvailable(Lorg/microemu/util/RecordStoreImpl;)I
    .locals 1
    .parameter "recordStoreImpl"

    .prologue
    .line 300
    const/high16 v0, 0x10

    return v0
.end method

.method public init()V
    .locals 0

    .prologue
    .line 220
    return-void
.end method

.method public init(Lorg/microemu/MicroEmulator;)V
    .locals 1
    .parameter "emulator"

    .prologue
    .line 93
    iput-object p1, p0, Lorg/microemu/app/util/FileRecordStoreManager;->emulator:Lorg/microemu/MicroEmulator;

    .line 94
    invoke-static {}, Ljava/security/AccessController;->getContext()Ljava/security/AccessControlContext;

    move-result-object v0

    iput-object v0, p0, Lorg/microemu/app/util/FileRecordStoreManager;->acc:Ljava/security/AccessControlContext;

    .line 95
    return-void
.end method

.method public listRecordStores()[Ljava/lang/String;
    .locals 6

    .prologue
    .line 191
    :try_start_0
    new-instance v4, Lorg/microemu/app/util/FileRecordStoreManager$3;

    invoke-direct {v4, p0}, Lorg/microemu/app/util/FileRecordStoreManager$3;-><init>(Lorg/microemu/app/util/FileRecordStoreManager;)V

    iget-object v5, p0, Lorg/microemu/app/util/FileRecordStoreManager;->acc:Ljava/security/AccessControlContext;

    invoke-static {v4, v5}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, [Ljava/lang/String;

    move-object v0, p0

    check-cast v0, [Ljava/lang/String;

    move-object v3, v0
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_0

    .line 200
    .local v3, result:[Ljava/lang/String;
    if-eqz v3, :cond_0

    .line 201
    array-length v4, v3

    if-nez v4, :cond_1

    .line 202
    const/4 v3, 0x0

    :cond_0
    move-object v4, v3

    .line 209
    .end local v3           #result:[Ljava/lang/String;
    :goto_0
    return-object v4

    .line 196
    :catch_0
    move-exception v4

    move-object v1, v4

    .line 197
    .local v1, e:Ljava/security/PrivilegedActionException;
    const-string v4, "Unable to access storeFiles"

    invoke-static {v4, v1}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 198
    const/4 v4, 0x0

    goto :goto_0

    .line 204
    .end local v1           #e:Ljava/security/PrivilegedActionException;
    .restart local v3       #result:[Ljava/lang/String;
    :cond_1
    const/4 v2, 0x0

    .local v2, i:I
    :goto_1
    array-length v4, v3

    if-ge v2, v4, :cond_0

    .line 205
    aget-object v4, v3, v2

    invoke-static {v4}, Lorg/microemu/app/util/FileRecordStoreManager;->fileName2RecordStoreName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    aput-object v4, v3, v2

    .line 204
    add-int/lit8 v2, v2, 0x1

    goto :goto_1
.end method

.method public openRecordStore(Ljava/lang/String;Z)Ljavax/microedition/rms/RecordStore;
    .locals 5
    .parameter "recordStoreName"
    .parameter "createIfNecessary"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 164
    new-instance v2, Ljava/io/File;

    invoke-direct {p0}, Lorg/microemu/app/util/FileRecordStoreManager;->getSuiteFolder()Ljava/io/File;

    move-result-object v3

    invoke-static {p1}, Lorg/microemu/app/util/FileRecordStoreManager;->recordStoreName2FileName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v2, v3, v4}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 168
    .local v2, storeFile:Ljava/io/File;
    :try_start_0
    invoke-direct {p0, v2}, Lorg/microemu/app/util/FileRecordStoreManager;->loadFromDisk(Ljava/io/File;)Lorg/microemu/util/RecordStoreImpl;
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 176
    .local v1, recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    :goto_0
    const/4 v3, 0x1

    invoke-virtual {v1, v3}, Lorg/microemu/util/RecordStoreImpl;->setOpen(Z)V

    .line 177
    iget-object v3, p0, Lorg/microemu/app/util/FileRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    if-eqz v3, :cond_0

    .line 178
    iget-object v3, p0, Lorg/microemu/app/util/FileRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    invoke-virtual {v1, v3}, Lorg/microemu/util/RecordStoreImpl;->addRecordListener(Ljavax/microedition/rms/RecordListener;)V

    .line 181
    :cond_0
    iget-object v3, p0, Lorg/microemu/app/util/FileRecordStoreManager;->testOpenRecordStores:Ljava/util/Hashtable;

    invoke-virtual {v2}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4, v1}, Ljava/util/Hashtable;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 183
    const/16 v3, 0x8

    invoke-virtual {p0, v3, p1}, Lorg/microemu/app/util/FileRecordStoreManager;->fireRecordStoreListener(ILjava/lang/String;)V

    .line 185
    return-object v1

    .line 169
    .end local v1           #recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    :catch_0
    move-exception v0

    .line 170
    .local v0, e:Ljava/io/FileNotFoundException;
    if-nez p2, :cond_1

    .line 171
    new-instance v3, Ljavax/microedition/rms/RecordStoreNotFoundException;

    invoke-direct {v3, p1}, Ljavax/microedition/rms/RecordStoreNotFoundException;-><init>(Ljava/lang/String;)V

    throw v3

    .line 173
    :cond_1
    new-instance v1, Lorg/microemu/util/RecordStoreImpl;

    invoke-direct {v1, p0, p1}, Lorg/microemu/util/RecordStoreImpl;-><init>(Lorg/microemu/RecordStoreManager;Ljava/lang/String;)V

    .line 174
    .restart local v1       #recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    invoke-direct {p0, v2, v1}, Lorg/microemu/app/util/FileRecordStoreManager;->saveToDisk(Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V

    goto :goto_0
.end method

.method public saveChanges(Lorg/microemu/util/RecordStoreImpl;)V
    .locals 3
    .parameter "recordStoreImpl"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreNotOpenException;,
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 214
    new-instance v0, Ljava/io/File;

    invoke-direct {p0}, Lorg/microemu/app/util/FileRecordStoreManager;->getSuiteFolder()Ljava/io/File;

    move-result-object v1

    invoke-virtual {p1}, Lorg/microemu/util/RecordStoreImpl;->getName()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Lorg/microemu/app/util/FileRecordStoreManager;->recordStoreName2FileName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 216
    .local v0, storeFile:Ljava/io/File;
    invoke-direct {p0, v0, p1}, Lorg/microemu/app/util/FileRecordStoreManager;->saveToDisk(Ljava/io/File;Lorg/microemu/util/RecordStoreImpl;)V

    .line 217
    return-void
.end method

.method public setRecordListener(Lorg/microemu/util/ExtendedRecordListener;)V
    .locals 0
    .parameter "recordListener"

    .prologue
    .line 304
    iput-object p1, p0, Lorg/microemu/app/util/FileRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    .line 305
    return-void
.end method
